{% extends "../../layui/layouts/blank.html" %}

{% block mainbody %}
<div class="admin-form form-block">
    <form class="layui-form layui-form-pane" lay-filter="_FORM">

        <div class="layui-form-item field-user-name">
            <label class="layui-form-label">头像</label>
            <div class="layui-input-block">
                <img class="layui-anim profile-avatar" id="avatar-img" src="{{Admin.Avatar}}">
                <input type="hidden" name="avatar" id="avatar-input" value="{{Admin.Avatar}}">
                <div class="layui-anim profile-avatar" id="avatar">编辑头像</div>
                <div class="help-block"></div>
            </div>
        </div>

        <div class="layui-form-item field-user-name">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" readonly="" name="username" lay-verify="required" value="{{Admin.Username}}">
                <div class="help-block"></div>
            </div>
        </div>

        <div class="layui-form-item field-user-username required">
            <label class="layui-form-label">昵称</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="nickname" lay-verify="required" value="{{Admin.Nickname}}">
                <div class="help-block"></div>
            </div>
        </div>

        <div class="layui-form-item field-user-username required">
            <label class="layui-form-label">通知方式</label>
            <div class="layui-input-block">
                <select id="menu-pid" class="layui-input" name="send_sms" autocomplete="off">
                    <option value="0" {% ifequal Admin.SendSms 0 %}selected{% endifequal %}>不开启短信提醒</option>
                    <option value="1" {% ifequal Admin.SendSms 1 %}selected{% endifequal %}>开启短信提醒</option>
                </select>
                <div class="help-block"></div>
            </div>
        </div>

        <div class="layui-form-item field-user-username required">
            <label class="layui-form-label">通知手机</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="phone" value="{{Admin.Phone}}">
                <div class="help-block"></div>
            </div>
        </div>

        <div class="layui-form-item layui-input-block">
            <button type="submit" class="layui-btn" lay-submit lay-filter="_SUBMIT_FORM">
                立即提交
            </button>
        </div>

    </form>
</div>
{% endblock %}

{% block script %}
<script>
    layui.use(['form', 'upload', 'ax', 'helper'], function() {
        var form = layui.form, ax = layui.ax, upload = layui.upload, $ = layui.jquery
        form.on('submit(_SUBMIT_FORM)', function (data) {
            var ajax = new ax("/profile", function(res) {
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index)
                parent.window.location.reload()
            });
            ajax.setMethod('post');
            ajax.setDataData(data.field);
            ajax.send();
            return false;
        })
        //执行实例
        var uploadInst = upload.render({
            elem: '#avatar' //绑定元素
            , url: '/avatar' //上传接口
            , done: function(res) {
                //上传完毕回调
                if (res.code === 0) {
                    var filename = res.data.filename
                    $('#avatar-img').attr("src", filename)
                    $('#avatar-input').val(filename)
                } else {


                }
            }
            , error: function(){
                //请求异常回调
            }
        });
    })
</script>
{% endblock %}